package com.atguigui.leetcode;

/**
 * 713.乘积小于 K 的子数组
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/5/5 8:57
 */
public class P713SubarrayProductLessThanK {
    public static void main(String[] args) {
        Solution solution = new P713SubarrayProductLessThanK().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int numSubarrayProductLessThanK(int[] nums, int k) {
            int n = nums.length, ret = 0;
            int prod = 1, i = 0;

            for (int j = 0; j < n; j++) {
                prod *= nums[j];
                while (i <= j && prod >= k) {
                    prod /= nums[i];
                    i++;
                }
                ret += j - i + 1;
            }


            return ret;
        }
    }
}
